# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:
        i = 0
        pre = ListNode(0)
        cc = pre
        while i < a:
            pre.next = list1
            pre = pre.next
            list1 = list1.next
            i +=1
        while list2:
            pre.next = list2
            pre = pre.next
            list2 = list2.next
        while i<=b:
            list1 = list1.next
            i+=1
        while list1:
            pre.next = list1
            list1 = list1.next
            pre = pre.next
        return  cc.next
